#include <iostream>
#include <string>
#include <stdlib.h>
#include <vector>
using namespace std;
#include <unistd.h>

string HostName()
{
    char* hostname =  getenv("HOSTNAME");
    if(hostname == nullptr)
        return "ULTS";
    return hostname;
}

string UsertName()
{
    char* username =  getenv("USER");
    if(username == nullptr)
        return "";
    return username;
}

string CurrentWorkDir()
{
    char* pwd =  getenv("PWD");
    if(pwd == nullptr)
        return "";
    return pwd;
}


void Interactive(string& out)
{
    cout <<UsertName() << "@" << HostName();
    cout << ":" << CurrentWorkDir() << "$ ";
    getline(cin,out);
}

void substring(string& out,char* argv[])
{
    size_t index = 0;
    size_t pos = 0;
    int i = 0;
    while(index < out.size())
    {
        pos = out.find(" ",pos);
        if(pos == string::npos)
        {
            argv[i++] =(char*)out.substr(index).c_str();
            break;
        }
        argv[i++] = (char*)out.substr(index,pos - index).c_str();
        index = ++pos;
    }
    argv[i] = nullptr;
}

int main()
{
    string out;
    char* argv[64];
    Interactive(out);
    substring(out,argv);
    for(int i = 0; argv[i] ; i++)
    {
        cout << argv[i] << endl;
    }
    return 0;
}

